package com.titanrise.crm.common.utils;

import com.titanrise.crm.domain.dto.UserDto;

import java.util.Map;
import java.util.regex.Pattern;

/**
 * @Description:
 * @Author: pront
 * @Time:2024-11-08 14:09
 */
public class ValidateUtil {

    /**
     * 校验密码合法性: 大写小写符号并且不少于8位的密码
     * @param password 密码
     * @return true - 合法  false - 违法
     */
    public static boolean passwordValid(String password) {
        String regex = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*(),.?\":{}|<>])(?=\\S+$).{8,20}$";
        return Pattern.matches(regex, password);
    }


    public static boolean usernameValid(String username, Map<Integer, UserDto> memberMap) {
        for (Map.Entry<Integer, UserDto> entry : memberMap.entrySet()) {
            if(username.equals(entry.getValue().getUsername())) return false;
        }
        return true;
    }
}
